package main

func findData(num1 []int, num2 []int) float64 {
	//处理长度短的数组
	if len(num1) > len(num2) {
		return findData(num2, num1)
	}
	low, high, k, num1mid, num2mid := 0, len(num1), (len(num1)+
		len(num2)+1)>>1, 0, 0
	num1mid = low + (high-low)>>1
	num2mid = k - num1mid
	if num1mid > 0 && num1[num1mid-1] > num2[num2mid] {
		//num1分界线划多了，左移动
		high = num1mid - 1
	} else if num1mid != len(num1) && num1[num1mid] < num2[num2mid] {
		low = num1mid + 1
	} else {
		//找到分界线，根据奇偶分析
	}
	midLeft, midRight := 0, 0
	if num1mid == 0 {
		midLeft = num2[num2mid-1]
	} else if num2mid == 0 {
		midLeft = num1[num1mid-1]
	} else {
		midLeft = max(num1[num1mid-1], num2[num2mid-1])
	}
	if (len(num1)+len(num2))&1 == 1 {
		midRight = num2[num2mid]
	} else if num2mid == len(num2) {
		midRight = num1[num1mid]
	} else {
		midRight = min(num1[num1mid], num2[num2mid])

	}
	return float64(midRight+midLeft) / 2
}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}
